//
// Ishtar C++ Utility Library
//
// Task Facility - Pooled Thread Header
//

#ifndef __ISHTAR_TASK_POOLED_THREAD_H
#define __ISHTAR_TASK_POOLED_THREAD_H

#include <Ishtar/Ishtar.h>

#if defined( ISHTAR_COMPILER_HAS_PRAGMA_ONCE )
#pragma once
#endif

#include <Ishtar/Mutex.h>
#include <Ishtar/Task/WorkImpl.h>
#include <Ishtar/Thread.h>
#include <Ishtar/Windows/SinglyLinkedList.h>


namespace Ishtar
{

namespace Task
{

class ThreadPoolImpl;

///////////////////////////////////////////////////////////////////////////////
//
// Pooled Thread
//

class PooledThread : public ThreadExecution
                   , public ::SLIST_ENTRY
{
public:
    PooledThread( ThreadPoolImpl* threadPool, Uint index );

    void Wake( const WorkImplPtr& work );
    void Stop();

private:
    std::string GetName() const { return m_name; }
    
    Int Execute();
    
    ThreadPoolImpl* m_threadPool;
    
    Uint        m_index;
    std::string m_name;
    Bool        m_stopped;
    
    WorkImplPtr m_runningWork;
    
    Mutex m_mutex;
    ConditionVariable m_waken;
};


///////////////////////////////////////////////////////////////////////////////

} // namespace Task

} // namespace Ishtar

#endif // __ISHTAR_TASK_POOLED_THREAD_H
